package com.zzw.hj8;

import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

/**
 * @Project: hw_java
 * @Description: 合并表记录
 * @Author: zzw
 */

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        Map<Integer, Integer> ms = new TreeMap<>();
        int n = in.nextInt();
        for (int i = 0; i < n; i++) {
            int key = in.nextInt();
            int val = in.nextInt();
            ms.merge(key, val, Integer::sum);
        }
        for (Integer i :
                ms.keySet()) {
            System.out.println(i + " " + ms.get(i));
        }
    }
}